package com.tang4j.model.factory;

import com.tang4j.core.model.Role;
import com.tang4j.core.model.easyui.TreeGrid;
import com.tang4j.core.util.InstanceUtil;
import com.tang4j.model.ThSysRole;

import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

public class RoleFactory {

    public static Role createRole(ThSysRole roleDto) {

        return new Role().setId(roleDto.getId()).setName(roleDto.getName()).setCode(roleDto.getCode());
    }

    public static List<Role> createRoleList(List<ThSysRole> thSysRoleList) {
        List<Role> roleList = new ArrayList<>();
        thSysRoleList.forEach(thSysRole -> roleList.add(RoleFactory.createRole(thSysRole)));
        return roleList;
    }

    public static TreeGrid createTreeGrid(ThSysRole thSysRole) {
        return new TreeGrid(String.valueOf(thSysRole.getId()), null, thSysRole.getName());
    }


    public static List<TreeGrid> createTreeGridList(@NotNull List<ThSysRole> thSysRoleList) {
        List<TreeGrid> treeGridList = InstanceUtil.newArrayList();
        thSysRoleList.forEach(thSysRole -> treeGridList.add(RoleFactory.createTreeGrid(thSysRole)));
        return treeGridList;
    }
}
